package sgd.tp2.api.cdr;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class CDRHandlerByteArray {

	public static byte[] getByteArrayFromCDR(CDR cdr) {
		ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
		ObjectOutputStream outStream = null;
		try {
			outStream = new ObjectOutputStream(bytesOut);
			outStream.writeObject(cdr);
		} catch (IOException e) {
		}

		return bytesOut.toByteArray();
	}

	public static CDR getCDRFromByteArray(byte[] bytes) throws IOException,
			ClassNotFoundException {
		return (CDR) (new ObjectInputStream(new ByteArrayInputStream(bytes))
				.readObject());
	}
}
